package com.k2data.k2app.common;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author lidong9144@163.com 17-4-10.
 */
@Component
public class MyConstant {

    public static final String EVENT_TYPE = "event";
    public static final String FAULT_TYPE = "fault";
    public static final String MAINTENANCE_TYPE = "maintenance";

    // dict
    public static final String DICT_DEVICE_STATUS_TYPE = "deviceStatus";
    public static final String DICT_FAULT_TYPE = "faultType";
    public static final String DICT_INDUSTRY_TYPE = "industry";
    public static final String DICT_DATA_SOURCE_TYPE = "dataSource";
    public static final String DEVICE_STATUS_PRIORITY = "priority";
    public static final String DEVICE_STATUS_OFFLINE = "不在线";
    public static final String DEVICE_STATUS_ALARM = "预警";
    public static final String DEVICE_STATUS_FAULT = "故障";

    // condition type
    public static final String COND_OWNER = "owner";
    public static final String COND_CUSTOMER_NO = "customerNo";
    public static final String COND_PROVINCE = "province";
    public static final String COND_CITY = "city";
    public static final String COND_REGION_NAME = "region_name";

    public static final Integer NOT_UPLOAD_KMX = 0;
    public static final Integer UPLOAD_KMX = 1;
    public static final Integer NOT_UPLOAD_KMX_NEW_FIELD = 2;

    public static final String KMX_ID_FIELD_FACTORY_NAME = "factory_id";
    public static final String KMX_ID_FIELD_FACTORY_NAME_DES = "工厂";   // customer
    public static final String KMX_ID_FIELD_EQUIPMENT_NAME = "equipment_id";
    public static final String KMX_ID_FIELD_EQUIPMENT_NAME_DES = "装置";   // device add field
    public static final String KMX_ID_FIELD_MACHINE_NAME = "machine_id";
    public static final String KMX_ID_FIELD_MACHINE_NAME_DES = "设备";   //deviceNo
    public static final String KMX_ID_FIELD_CHANNEL_TYPE = "channel_type";
    public static final String KMX_ID_FIELD_CHANNEL_TYPE_DES = "0-c_vib-振动量, 1-c_sta_过程量, 2-modbus过程量, 3-开关量,4 c_oil_sensor 油液传感器";
    public static final String KMX_ID_FIELD_CHANNEL_ID = "channel_id";
    public static final String KMX_ID_FIELD_CHANNEL_ID_DES = "通道id";
    public static final String KMX_ID_FIELD_DATA_TYPE = "datatype";
    public static final String KMX_ID_FIELD_DATA_TYPE_DES = "类型";


    @Getter
    @Value("${kmx.fieldGroups.url}")
    private String fieldGroupsUrl;
    @Getter
    @Value("${kmx.postData.url}")
    private String postDataUrl;
    @Getter
    @Value("${kmx.assets.url}")
    private String assetsUrl;
    @Getter
    @Value("${kmx.dataRows.url}")
    private String dataRowsUrl;
    @Getter
    @Value("${kmx.dataRows.real-time-url}")
    private String dataRowsRealTimeUrl;
    @Getter
    @Value("${kmx.dataPoints.url}")
    private String dataPointsUrl;
    @Getter
    @Value("${kmx.dataStreams.url}")
    private String dataStreamsUrl;
    @Getter
    @Value("${kmx.dataStreams.real-time-url}")
    private String dataStreamsRealTimeUrl;
    @Getter
    @Value("${kmx.rules.url}")
    private String streamRuleUrl;

    /**
     * 查询fileldGroup名称规则，1表示在表名称前面加前缀 2表示不加前缀  kmx.fieldGroup.rule.before表示前缀名称
     */
    @Getter
    @Value("${kmx.fieldGroupId.rule}")
    private String groupIdRule;

    @Getter
    @Value("${kmx.fieldGroupId.name}")
    private String groupIdName;


    public String getFieldGroup(String nameEn){
        // tcs 特殊处理
        if (nameEn.startsWith("tcs")) {
            if(getGroupIdRule() == null || getGroupIdRule().equals("2")){
                String a = Joiner.on("_").join(Splitter.on('_')
                        .trimResults()
                        .omitEmptyStrings()
                        .splitToList(nameEn).subList(0, 2));
                return a;
            }else{
                String a = Joiner.on("_").join(Splitter.on('_')
                        .trimResults()
                        .omitEmptyStrings()
                        .splitToList(nameEn).subList(0, 2));
                return getGroupIdName()+"_"+a;
            }

        }
        else{
            return nameEn;
        }
    }
}
